package com.ff.controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ff.model.Fuser;
import com.ff.model.Shop;
import com.ff.model.Wares;

@Controller
@RequestMapping("/shop")
public class ShopContorller extends AllController {
	@RequestMapping("/cdselectall")//分页查询用户数据
	public String cdselectall(ModelMap mm,int id) {
		int count=sservice.find_();
		mm.put("count", count);
		if(id<1)
			id=1;
		if(id>count)
			id=count;
		System.out.println(1);
		List<Shop> listss=sservice.find_limit(id);
		mm.put("shop", listss);
		mm.put("ts",id);
		return "f_shop";
	}
	
	@RequestMapping("/cdjumpinsert")//跳转到后台添加页面
	public String cdjumpinsert() {
		return "f_shop_insert";
	}
	
	@RequestMapping("/cdinsert")//后台添加数据
	public String cdinsert(Shop s) {
		String cd="shop";
		sservice.insert11(s);
		return "redirect:/fuser/cdjump00?cd="+cd;
				
	}
	
	@RequestMapping("/cdjumpupdate")//跳转到后台修改页面
	public String cdjumpupdate(ModelMap mm,int id) {
		Shop f=sservice.find11(id);
		mm.put("shop", f);
		return "f_shop_update";
	}
	
	@RequestMapping("/cdupdate")//后台修改数据
	public String cdupdate(ModelMap mm,Shop s) {
		String cd="shop"; 
		sservice.update11(s);
		return "redirect:/fuser/cdjump00?cd="+cd;
	}
	
	@RequestMapping("/cddelete")//后台删除数据
	public String cddelete(int id) {
		String cd="shop";
		sservice.delete01(id);
		return "redirect:/fuser/cdjump00?cd="+cd;
	}
	
	@RequestMapping("/selectall")//查询购物车数据
	public String selectall(ModelMap mm,int uid) {
		List<Shop> shop=sservice.find12(uid);
		if(shop!=null) {
			
		System.out.println(shop.toString());
		for(Shop ss:shop) {
			Fuser fuser=fservice.find11(ss.getFid());
			Wares w=wservice.find11(ss.getWid());
			ss.setFuser(fuser);
			ss.setWares(w);
		}
		
		mm.put("shop",shop);
		}
		return "personal-record";
		
	}
	@RequestMapping("/deleteid")//购物车内商品的购买
	public String delete(ModelMap mm,int id) {
		Shop shop=sservice.find11(id);
		Wares w=wservice.find11(shop.getWid());
		w.setWinventory(w.getWinventory()-1);
		w.setFsell(w.getFsell()+1);
		wservice.update11(w);
		shop.setStat(1);
		sservice.update11(shop);
		return "redirect:/shop/selectall?uid="+shop.getFid();
	}
}
